<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>订单促销列表</title>
    <!--{include file='comm/comm_cal.tpl'}-->
</head>
<body>

<div class="container">

        <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" class="form-inline"  onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span>促销名称：<input type="text" id="title" class="form-control input-sm"  name="title" value="" style="width:148px;"/></span>
                                    <span>
                                        促销类型：<select id="type" class="form-control input-sm"  name="type" style="width:100px;">
                                            <option value="0">请选择</option>
                                            <option value="1">立减</option>
                                            <option value="2">免运费</option>
                                            <option value="3">优惠券</option>
                                            <option value="4">折扣</option>
                                        </select>
                                    </span>
                                    <span>促销日期：<input id="startDate" class="form-control input-sm"  name="startDate" value="" type='text' style="width:120px;" readonly ></span>
                                    <button type="button" class="btn btn-default btn-sm" onclick="promotion.timeClear();">清 空</button>
                                    <span><input type="button" value="查询" class="btn btn-primary"  onclick="promotion.search();" /></span>
                                    <span><input  class="btn btn-warning" id="startDateBtn" name="startDateBtn" type="button" onclick="promotion.clear();" value="重置"></span>

                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>


</div>

<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/promotion/promotionBill.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            <!--{if $edit_permission}-->
            {display: "操作", width : 100, align: "center"},
            <!--{/if}-->
            {display: "促销号", name : "promotionID", width : 100, sortable : true},
            {display: "促销标题", width : 260},
            {display: "活动类型", width : 120},
            {display: "开始日期", width : 150 , align: "center"},
            {display: "结束日期", width : 150 , align: "center"},
            <!--{if $edit_permission}-->
            {display: "使用状态", width : 80  , align: "center"}
            <!--{/if}-->
        ],
        <!--{if $edit_permission}-->
        buttons : [
            {name: "添加", bclass: "add", onpress : "promotion.add"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "promotion.deletePromotionBill"},
            {separator: true},
            {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
            {separator: true},
            {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}
        ],
        <!--{/if}-->
        sortname: "promotionID",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var promotion = {

        delete_str: "" ,
        useFlg_str : "" ,

        //搜索订单促销
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        //添加订单促销
        add: function() {
            E.open("/quanliadmin/app/promotion/promotionBill.pscript?operFlg=100", "", {height: 600,width: 1024, top: 50, left: 150});
        },
        clear:function (){
            $("#title").val("");
            $("#type").val("0");
            $("#startDate").val("");
            this.search();
        },
        timeClear: function() {
            $('#startDate').val('');
        },
        deletePromotionBill: function() {
            this.delete_str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    promotion.delete_str += "_" + $(v).attr("id").replace("row", "");
                }
            });

            if (this.delete_str == "")
                E.alert("请选择删除订单促销");
            else
                E.confirm("您确认要删除选中的订单促销吗？", "promotion.deleteConfirm");
        },

        doAction: function( promotionID , useFlg ) {
            this.useFlg_str = promotionID + "_" + useFlg ;
            if( useFlg == 0 )
                E.confirm("您确认要禁用订单促销吗？", "promotion.actionConfirm");
            else

                E.confirm("您确认要启用订单促销吗？", "promotion.actionConfirm");
        },

        actionConfirm : function () {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/promotion/promotionBill.ajax?operFlg=100&useFlg_str=" + promotion.useFlg_str+"&act=change",
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "promotion.load");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        deleteConfirm: function() {
            this.delete_str = this.delete_str.substr(1);
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/promotion/promotionBill.ajax?operFlg=100&delete_str=" + promotion.delete_str+"&act=del",
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "promotion.load");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        edit: function(promotionID) {
            E.open("/quanliadmin/app/promotion/promotionBill.pscript?operFlg=101&promotionID=" + promotionID, "", {height: 600,width: 1024, top: 50, left: 150});
        },

        config: function(promotionID) {
            E.open("/quanliadmin/app/promotion/promotionBill.pscript?operFlg=102&promotionID=" + promotionID, "", {height: 600,width: 1024, top: 50, left: 150});
        },

        load: function() {
            $("#flex").flexReload();
        }

    };
    
    
	$('#startDate').datetimepicker();

</script>

</body>
</html>